﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using crm_dal.Objects;
using crm_library.Javascript;


namespace crm_web.DataPages
{
	public partial class EditClient : System.Web.UI.Page
	{
		Client displayClient;

		protected void Page_Init(object sender, EventArgs e)
		{
			try
			{
				displayClient = new Client(Convert.ToInt32(HttpContext.Current.Session["Selection"]));
				txtFname.Text = displayClient.FirstName;
				txtMiddleInit.Text = displayClient.MiddleInit;
				txtLname.Text = displayClient.LastName;
				txtCompany.Text = displayClient.Company;
			}
			catch (Exception ex)
			{
				Alert.Show(ex.Message, Alert.AlertMessageType.Error);
			}
		}

		protected void btnUpdate_Click(object sender, EventArgs e)
		{
			string error = "";
			try
			{
				displayClient.FirstName = txtFname.Text.Trim();
				displayClient.LastName = txtLname.Text.Trim();
                displayClient.MiddleInit = txtMiddleInit.Text.Trim();
				displayClient.Company = txtCompany.Text.Trim();
				displayClient.Update();
			}
			catch (Exception ex)
			{
				error = ex.Message;
			}

			if (!String.IsNullOrWhiteSpace(error))
			{
				Alert.Show(error, Alert.AlertMessageType.Error);
			}
			else
			{
				Alert.Show("edit succeeded", Alert.AlertMessageType.Message, "/DataPages/Clients.aspx");
			}
		}
	}
}